package cn.lj.logistics.mapper;

import cn.lj.logistics.pojo.BaseData;
import cn.lj.logistics.pojo.BaseDataExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface BaseDataMapper {
    @Delete({
        "delete from t_base_data",
        "where base_id = #{baseId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long baseId);

    @Insert({
        "insert into t_base_data (base_id, base_name, ",
        "base_desc, parent_id)",
        "values (#{baseId,jdbcType=BIGINT}, #{baseName,jdbcType=VARCHAR}, ",
        "#{baseDesc,jdbcType=VARCHAR}, #{parentId,jdbcType=BIGINT})"
    })
    int insert(BaseData record);

    @InsertProvider(type=BaseDataSqlProvider.class, method="insertSelective")
    int insertSelective(BaseData record);

    @SelectProvider(type=BaseDataSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="base_id", property="baseId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="base_name", property="baseName", jdbcType=JdbcType.VARCHAR),
        @Result(column="base_desc", property="baseDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="parent_id", property="parentId", jdbcType=JdbcType.BIGINT)
    })
    List<BaseData> selectByExample(BaseDataExample example);

    @Select({
        "select",
        "base_id, base_name, base_desc, parent_id",
        "from t_base_data",
        "where base_id = #{baseId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="base_id", property="baseId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="base_name", property="baseName", jdbcType=JdbcType.VARCHAR),
        @Result(column="base_desc", property="baseDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="parent_id", property="parentId", jdbcType=JdbcType.BIGINT)
    })
    BaseData selectByPrimaryKey(Long baseId);

    @UpdateProvider(type=BaseDataSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(BaseData record);

    @Update({
        "update t_base_data",
        "set base_name = #{baseName,jdbcType=VARCHAR},",
          "base_desc = #{baseDesc,jdbcType=VARCHAR},",
          "parent_id = #{parentId,jdbcType=BIGINT}",
        "where base_id = #{baseId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(BaseData record);

    @Select("select c.base_id baseId,c.base_name baseName from  t_base_data c left join t_base_data p on c.parent_id = p.base_id where p.base_name = #{parentName}")
	List<BaseData> selectBaseDatasByParentName(String parentName);
}